package com.cea.papyrus.core.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontData;

import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.utils.Debug;


/**
 * this is the figure to represent a class
 * @author Arnaud Cuccuru
 * @since 13 fevrier 2007
 */
public class TemplateSignatureFigure extends NodeFigure {

	private Figure contentPane;

	/* this is the containee of template parameters*/
	private TemplateParamContainerFigure templateParameterContent;


	/**
	 * this the constructor of a class figure
	 *
	 */
	public TemplateSignatureFigure() {
		super();
		remove(nameLabel);
		ToolbarLayout layout = new ToolbarLayout();
		layout.setVertical(true);
		this.setLayoutManager(layout);
		layout.setSpacing(5);

		Rectangle rect = getBounds().getCopy() ;
		rect.height = rect.height - 50 ;
		setBounds(rect) ;

		this.setOpaque(true); // non-transparent figure

		// The area accepting inner figures.
		this.createContentPane();	
	}



	/**
	 * add the property container in the class figure
	 * @param propertyContent the poperty container
	 */ 
	public void addtemplateParameterContainer(TemplateParamContainerFigure templateParameterContent){
		this.templateParameterContent=templateParameterContent;

	}

	/**
	 * to obtain the property container of the class figure
	 * @return property container of the class figure
	 */
	public TemplateParamContainerFigure getTemplateParameterContent(){
		return this.templateParameterContent;}


	/**
	 * Get the inner figure accepting childs figure.
	 * @return the contentPane of the class
	 */
	public IFigure getContentPane()
	{
		return this.contentPane;	
	}

	/**
	 * used to create a container to add child figure in the class
	 *
	 */

	protected void createContentPane()
	{
		this.contentPane = new Figure();
		//this.contentPane.setOpaque(false);
		this.add(this.contentPane);

	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Figure#setBounds(org.eclipse.draw2d.geometry.Rectangle)
	 */
	@Override
	public void setBounds(Rectangle rect) {
		//rect.height = rect.height - 50 ;
		super.setBounds(rect);

		Rectangle myRect= rect.getCopy();
		myRect.crop(new Insets(10));
		if(this.getContentPane()!=null){
			this.getContentPane().setBounds(myRect);
		}
		// calculate property Content size
		myRect= rect.getCopy();
		myRect.crop(new Insets(10));
		Debug.debug(this, "parent "+this.getBounds(),30);
		if (this.getTemplateParameterContent()!=null){
			this.getTemplateParameterContent().setBounds(myRect);
			Debug.debug(this, "container: "+this.getContentPane().getBounds(),30);
			Debug.debug(this, "ParamList"+this.getTemplateParameterContent().getBounds(),30);
		}

	}

	int [] dashes = new int[10] ;

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Figure#paint(org.eclipse.draw2d.Graphics)
	 */
	@Override
	public void paint (Graphics graphics) {
		super.paint (graphics);
		//Figure f;

		Rectangle rect=getBounds().getCopy() ;
		rect.height = rect.height-1 ;
		rect.width = rect.width-1 ;

		for (int i=0 ; i<10 ; i++) {
			dashes[i] = 5 ;
		}
		graphics.setLineDash(dashes) ;
		graphics.drawRectangle(rect) ;


	}

	/**
	 * to display the Class as abstract
	 * @param b yes for abstract no other
	 */
	public void setAbstract(boolean b){

		if (b) {
			FontData[] font={new FontData(getfigureFont(), getFontSize(), SWT.ITALIC|SWT.BOLD)};
			this.getNameLabel().setFont(PapyrusPlugin.fontManager.get(font));//italic
		} else {
			FontData[] font={new FontData(getfigureFont(), getFontSize(), SWT.BOLD)};
			this.getNameLabel().setFont( PapyrusPlugin.fontManager.get(font));
		}
	}
	public void setBackgroundColor(Color backgroundColor) {
		this.setOpaque(true);
		this.backgroundColor = ColorConstants.white;
		if(getTemplateParameterContent()!=null){
		getTemplateParameterContent().setBackgroundColor(backgroundColor);}
		super.setBackgroundColor(backgroundColor);
		getContentPane().setBackgroundColor(backgroundColor);
	}
}
